{% load questions_extra %}

{% if random_questions %}
	
	

	
	<form id="questions" action="/show_results/"  method="POST">
	{% for rand_question in random_questions %}
	 <table class="question" id="question_{{forloop.counter}}">
	 	<tr>
	 	
        	<th colspan="2" height="100"> {{ rand_question.title }}
        	    {% ifnotequal rand_question|correct_answer_count 1 %}
        	    <br></br>
            		<br>Please tick {{rand_question|correct_answer_count}} answers</br>
            	{% endifnotequal %}
        	</th>
            <th></th>
            <th></th>
            <th>Question {{forloop.counter}} of {{random_questions.count}}</th>
            {% if rand_question.image %}
    			 <th>
    			 <div align="right"><img src="/site_media/images/{{ rand_question.image }}" alt="{{ rand_question.image }}"/></div></th>
    		{% endif %}
            </tr>
            
	
		
			{% if random_question|is_multiselect:rand_question.id %}
				{% for answer in rand_question.all_answers_set.select_related %}
					{%	if forloop.counter|divisibleby:"2" %}
					<td><input type="checkbox" name="question_{{ rand_question.id }}" value="{{ answer.id }}"/> </td> <td width="350">  <label for="question_{{ rand_question.id }}">{{answer.answer}}</label></td>
            		</tr>
            		{% else %}
            		<tr>
                  	<td><input type="checkbox" name="question_{{ rand_question.id }}" value="{{ answer.id }}"/> </td> <td width="350"> <label for="question_{{ rand_question.id }}">{{answer.answer}}</label></td>
                  	<td width="30"></td>
                  		{% if forloop.last %}
                  			</tr>
                  		{% endif %}
            		{% endif %}
				{% endfor %}
			{% else %}
				{% for answer in rand_question.all_answers_set.select_related %}
					{%	if forloop.counter|divisibleby:"2" %}
					<td><input type="radio" name="question_{{ rand_question.id }}" value="{{ answer.id }}"/> </td> <td width="350">  <label for="question_{{ rand_question.id }}">{{answer.answer}}</label></td>
            		</tr>
            		{% else %}
            		<tr>
                  	<td><input type="radio" name="question_{{ rand_question.id }}" value="{{ answer.id }}"/> </td> <td width="350"> <label for="question_{{ rand_question.id }}">{{answer.answer}}</label></td>
                  	<td width="30"></td>
                  		{% if forloop.last %}
                  			</tr>
                  		{% endif %}
            		{% endif %}
				{% endfor %}
			{% endif %}
    		 
    		 
    	   	<tr>
                <td colspan="5" >
                 	<div class="prevnext">
    		{%  if forloop.first %}
                    <input type="button" value="" class="next" onClick="$('#question_{{forloop.counter}}').hide('fast');$('#question_{{forloop.counter|add:"1"}}').show('fast')" />              
			{% else %}
				{% if forloop.last %}
					<input type="button"  class="previous"  onclick="$('#question_{{forloop.counter}}').hide('fast');$('#question_{{forloop.counter|add:"-1"}}').show('fast')"" />
					<input type="submit" class="check_results" value=""  />
				{% else %}
					<input type="button"  class="previous"  onclick="$('#question_{{forloop.counter}}').hide('fast');$('#question_{{forloop.counter|add:"-1"}}').show('fast')"" />
					<input type="button"  class="next" onclick="$('#question_{{forloop.counter}}').hide('fast');$('#question_{{forloop.counter|add:"1"}}').show('fast')"" />
				{% endif %}
			{% endif %}
			   </div></td>
            </tr>
		 </table>
	{% endfor %}
	</form>
	
	<script type="text/javascript">	 
		jQuery('table').filter('.question').hide();	 
		jQuery('#question_1').show();
	</script>
	
{% else %}
<p>No questions in database.</p>
{% endif %}